import { CreateWorkflowRequest, Workflow, ListWorkflowsRequest,ListWorkflowsResponse, DeleteWorkflowRequest, GetWorkflowRequest, UpdateWorkflowRequest } from "@/types/proto/api/v1/workflow_service";

import { workflowServiceClient} from "./grpcweb_auth";
import { Empty } from "@/types/proto/google/protobuf/empty";

export async function CreateWorkflow(data: CreateWorkflowRequest): Promise<Workflow> {
  try {
    return workflowServiceClient.createWorkflow(data)
  } catch (error) {
    console.error('gRPC request failed:', error);
    throw error;
  }
}

export async function UpdateWorkflow(data: UpdateWorkflowRequest): Promise<Workflow> {  
  try {
    return workflowServiceClient.updateWorkflow(data)
  } 
  catch (error) {
    console.error('gRPC request failed:', error);
    throw error;
  }
}

export async function ListWorkflows(data: ListWorkflowsRequest): Promise<ListWorkflowsResponse> {
  try {
    return workflowServiceClient.listWorkflows(data)
  } 
  catch (error) {
    console.error('gRPC request failed:', error);
    throw error;
  }
}

export async function GetWorkflow(data:GetWorkflowRequest): Promise<Workflow> {
  try {
    return workflowServiceClient.getWorkflow(data)
  } 
  catch (error) {
    console.error('gRPC request failed:', error);
    throw error;
  }
}

export async function DeleteWorkflow(data: DeleteWorkflowRequest): Promise<Empty> {
  try {
    return workflowServiceClient.deleteWorkflow(data)
  } 
  catch (error) {
    console.error('gRPC request failed:', error);
    throw error;
  }
}